﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;
using System.Xml.Serialization;

namespace zEngine.Particles
{
    public class ParticleElement
    {
        public Vector3 StartingPosition;
        public List<ParticleVertex> Vertices;

        float randomValue;
        public float timeCreated;
        public float lifeTime;
        Vector3 direction;

        /// <summary>
        /// Initializes a new instance of the ParticleElement class.
        /// </summary>
        /// <param name="istartingPosition"></param>
        public ParticleElement(Vector3 istartingPosition, float itimeCreated, float ilifeTime, Vector3 dir)
        {
            StartingPosition = istartingPosition;
            timeCreated = itimeCreated;
            lifeTime = ilifeTime;

            Vertices = new List<ParticleVertex>();

            // Prepare our value
            Random rnd = new Random((int)DateTime.Now.Ticks);
            randomValue = DataType.NextFloat(rnd) / 4 * 3 + 0.25f; // Move the random from [0.25 -> 1.0]

            direction = new Vector3(
                    DataType.NextFloat(rnd) - 0.5f + dir.X, DataType.NextFloat(rnd) - 0.5f + dir.Y, DataType.NextFloat(rnd) - 0.5f +dir.Z
                );
            direction.Normalize();

            Vertices.Add(new ParticleVertex(StartingPosition, new Vector2(1, 1), timeCreated, lifeTime, direction, randomValue));
            Vertices.Add(new ParticleVertex(StartingPosition, new Vector2(0, 0), timeCreated, lifeTime, direction, randomValue));
            Vertices.Add(new ParticleVertex(StartingPosition, new Vector2(1, 0), timeCreated, lifeTime, direction, randomValue));

            Vertices.Add(new ParticleVertex(StartingPosition, new Vector2(1, 1), timeCreated, lifeTime, direction, randomValue));
            Vertices.Add(new ParticleVertex(StartingPosition, new Vector2(0, 1), timeCreated, lifeTime, direction, randomValue));
            Vertices.Add(new ParticleVertex(StartingPosition, new Vector2(0, 0), timeCreated, lifeTime, direction, randomValue));
        }

    }
}
